package com.example.viewtest.ActivityGroup;

import androidx.appcompat.app.AppCompatActivity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.viewtest.Dao.MessageEvent;
import com.example.viewtest.DialogGroup.diaLogTest;
import com.example.viewtest.R;
import com.example.viewtest.Tools.BaseActivity;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class DiaLogActivity extends BaseActivity {
    private TextView mTextView;
    private String mdata;

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(MessageEvent event) {
        mdata = event.message;
        Toast.makeText(DiaLogActivity.this, event.message, Toast.LENGTH_SHORT).show();
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dia_log);
        //获取活动的text view
        mTextView = this.findViewById(R.id.data_dialog_callback);
        Button button1 = this.findViewById(R.id.button_dialog);
        button1.setOnClickListener(v -> {
            //自定义对话框
            diaLogTest myDiaLog = new diaLogTest
                    (DiaLogActivity.this,"早上9点","晚上八点","精神磨练");

            myDiaLog.setYesOnclickListener("确认", new diaLogTest.onYesOnclickListener() {
                @Override
                public void onYesClick() {
                    Toast.makeText(DiaLogActivity.this,"你确认了",Toast.LENGTH_SHORT).show();
                    mTextView.setText(mdata);
                    myDiaLog.dismiss();
                }
            });
            myDiaLog.setNoOnclickListener("取消", new diaLogTest.onNoOnclickListener() {
                @Override
                public void onNoClick() {
                    Toast.makeText(DiaLogActivity.this,"你取消了",Toast.LENGTH_SHORT).show();
                    myDiaLog.dismiss();
                }
            });
            myDiaLog.setGoToAnotherActivityOnclickListener(new diaLogTest.onGoToAnotherActivityOnclickListener() {
                @Override
                public void onGoToClick() {
                    Toast.makeText(DiaLogActivity.this,"隐式打开主Activity",Toast.LENGTH_SHORT).show();
                }
            });

            myDiaLog.show();
            //系统自带对话框
//            AlertDialog alertDialog = new AlertDialog.Builder(DiaLogActivity.this)
//                    .setIcon(R.drawable.icon_wait_loading)
//                    .setTitle("弹出对话框")
//                    .setMessage("对话框测试内容")
//                    .setPositiveButton("确定", new DialogInterface.OnClickListener() {
//                        @Override
//                        public void onClick(DialogInterface dialog, int which) {
//                            Toast.makeText(DiaLogActivity.this, "点击了确定的按钮", Toast.LENGTH_SHORT).show();
//                            dialog.dismiss();
//                        }
//                    })
//                    .setNegativeButton("取消", new DialogInterface.OnClickListener() {
//                        @Override
//                        public void onClick(DialogInterface dialog, int which) {
//                            Toast.makeText(DiaLogActivity.this, "点击了取消按钮", Toast.LENGTH_SHORT).show();
//                            //对话框消失
//                            dialog.dismiss();
//                        }
//                    }).create();
//            Window window = getWindow();
//            window.setWindowAnimations(R.style.mystyle);
//            alertDialog.show();
//            //第二种写法，创建Builder实例
////            AlertDialog.Builder alertDialog = new AlertDialog.Builder(DiaLogActivity.this);
        });

    }

    @Override
    public void onStart() {
        super.onStart();
        EventBus.getDefault().register(this);
    }

    @Override
    public void onStop() {
        EventBus.getDefault().unregister(this);
        super.onStop();
    }
}